package com.ruoyi.buss.grid.sq.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.buss.grid.sq.domain.DataWgWgsq;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.system.api.model.LoginUser;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.buss.grid.sq.domain.DataWgWgsqSqgl;
import com.ruoyi.buss.grid.sq.service.IDataWgWgsqSqglService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 网格社区管户Controller
 * 
 * @author sxy
 * @date 2021-07-16
 */
@RestController
@RequestMapping("/sqgh")
public class DataWgWgsqSqglController extends BaseController
{
    @Autowired
    private IDataWgWgsqSqglService dataWgWgsqSqglService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询网格社区管户列表
     */
    @PreAuthorize(hasPermi = "buss:sqgh:list")
    @GetMapping("/list")
    public TableDataInfo list(DataWgWgsqSqgl dataWgWgsqSqgl)
    {
        LoginUser userInfo = tokenService.getLoginUser();
        startPage();
        List<DataWgWgsqSqgl> list = dataWgWgsqSqglService.selectDataWgWgsqSqglList(dataWgWgsqSqgl,userInfo);
        return getDataTable(list);
    }

    /**
     * 获取社区的小区或者社区
     * type  1社区 2小区
     */
    @ApiOperation(value="获取社区的小区或者社区",tags={"获取社区的小区或者社区"},notes="type  1上级社区或乡镇 2小区")
    @PreAuthorize(hasPermi = "buss:selectSqOrXq:list")
    @GetMapping("/selectSqOrXq")
    public List<DataWgWgsqSqgl> selectSqOrXq(@Validated DataWgWgsqSqgl dataWgWgsqSqgl)
    {
        LoginUser userInfo = tokenService.getLoginUser();

//        startPage();
        List<DataWgWgsqSqgl> list = dataWgWgsqSqglService.selectDataWgWgsqList(dataWgWgsqSqgl,userInfo);
        return list;
    }

    /**
     * 导出网格社区管户列表
     */
    @PreAuthorize(hasPermi = "buss:sqgh:export")
    @Log(title = "网格社区管户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataWgWgsqSqgl dataWgWgsqSqgl) throws IOException
    {
        LoginUser userInfo = tokenService.getLoginUser();
        List<DataWgWgsqSqgl> list = dataWgWgsqSqglService.selectDataWgWgsqSqglList(dataWgWgsqSqgl,userInfo);
        ExcelUtil<DataWgWgsqSqgl> util = new ExcelUtil<DataWgWgsqSqgl>(DataWgWgsqSqgl.class);
        util.exportExcel(response, list, "网格社区管户数据");
    }

    /**
     * 获取网格社区管户详细信息
     */
    @PreAuthorize(hasPermi = "buss:sqgh:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(dataWgWgsqSqglService.selectDataWgWgsqSqglById(id));
    }

    /**
     * 新增网格社区管户
     */
    @PreAuthorize(hasPermi = "buss:sqgh:add")
    @Log(title = "网格社区管户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataWgWgsqSqgl dataWgWgsqSqgl)
    {
        return toAjax(dataWgWgsqSqglService.insertDataWgWgsqSqgl(dataWgWgsqSqgl));
    }

    /**
     * 修改网格社区管户
     */
    @PreAuthorize(hasPermi = "buss:sqgh:edit")
    @Log(title = "网格社区管户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataWgWgsqSqgl dataWgWgsqSqgl)
    {
        return toAjax(dataWgWgsqSqglService.updateDataWgWgsqSqgl(dataWgWgsqSqgl));
    }

    /**
     * 删除网格社区管户
     */
    @PreAuthorize(hasPermi = "buss:sqgh:remove")
    @Log(title = "网格社区管户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(dataWgWgsqSqglService.deleteDataWgWgsqSqglByIds(ids));
    }
}
